package pkg

import (
	"fmt"
	"github.com/smartwalle/alipay/v3"
)

type Pay interface {
	VipPay() string
}
type AliPay struct {
	Price   float64
	Title   string
	OrderNo string
}

func (Ali *AliPay) VipPay() string {
	var privateKey = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDUUvJyynuGPEhw369lXZsn4UBFtJEE0xhbmZ0UrYkGnGGmbIMvFWNS4yhR32JibVKXi07WI76tHOEbu0kVcWoIZ1P87Xt7RXwvbl+e+9VsCLyjp0YEL9mEflDha97cnuV9Saxzf5xIgR1LTbSF4++tpph7zOQtGhKahvndIiOO6Ija6eQgwpnJDio5IeH5k5fAl0JtTtZE0RTTKtI7vS5/uBwUP7BRnvi4t3VF9eg9pjOlaEr59kkJGJTH3m+dnXv1+dhHT9E97ecjXN0sVLeV/R/qTgSKABN1NopG9dFor8PPbHV39tjqajxwAc7U4ri4tLw9/PBUTX934GDSzHE1AgMBAAECggEAW8rEcGYjgwQa2VmLLYqLYnFaZQhMTcapWCiQJXlkrQv8l4OAL2HSv+ne645krWLP+x5J5gAsFhFPLLsKPI/8pEdvowBUixWeO68+/a+oM/2O+D1/4p2BL2ugseP9xGmZk1G/kWtQ+HOBY6XjbqL9YpiMgbEx0GHeOxoxea2hq80Ih7FED0aYjn2A4t7TBxTY6LuVPPdaPdBBpZxkMQPMWRyfuxJgMRL2oh+9Jj73Kxqqzf0DhoYQKyFm/OncOZXgZYBz9n3u09XCGUEvitefPz0hsLTYY05WVTFZZOUTljdxBKh/WjeGybUeEULga1Cb4Fm96cmnZ/D4GCn8UiE4HQKBgQDtLOKKfyhzT+I4X3SpuCIp0lt8J1phM3ar3hygbdCB3wNViCKrDgimmimjmI2/LAVk7a2WrO/PsgG3MWpIlT8O+AW9CoTQxEVQjp+yYzVwPY9D4wDe+GvR7AB9KLY2WPVmueHJI2T8lZbv7kap+CU/7tlynmXCug7W6WcjadsaMwKBgQDlLR0L3iInE/KRCFjbbUHCPBP7nQFyxXOIhOO/fm5fzPGYIp101o48mvMz617gmGSD3M2eqk97mOg0qLTjzichF1p5KTSF/lHuJuk8D6IJx4sGwiYKann1C+k8apD0wyJ3pbcE0Q0z77z5cy8+JD77yLsJsXLKc6ITGcx6iIsu9wKBgGiYUNfPOCGSayt9PU/Tuo1DDcF1AXC4Z29oJqvBgiCkHy5LOS7Co6IFfrN9BZX3bfGSt+kpHyEzWXpWuo6D8ylAzBcQWn5O8FqUa20aP2jeXR4NMEckuzf6okSP/bt+A8tn0mEH0PNrbQMmy9cNbjABv7fCjxIPR5gTmr6NYmjtAoGBAKdpFyjOMeCd/7nWgSJ5Y2oB/Q72mFJAzq7RdJU0RGiTC4D4+FCbUvgOsM4iiAJFEFgK+eGHw9wjzKx6+PjYZVkU+DA923JuX2c64XHQcav3KiXbuXIuabyJ4O0TY6SIzyrb0SAhniVsYX1PmRkp3SCMd6UTDSm64pBVbjusdw/tAoGBALcUeWmBolSlIQGgUjIhY2TVjVh+rCydITHuiOMQmAWgRXhcUJJShHqJbOuUJzoTVD/ive1eI+jdkv6I7QY43NdglP4TMTGXu0BRrv7THdmMRTRDqPCZ7vo6c+7v0rUiVv8e3K2DpDwfXZGJbDG0wkYVHFi5jZCFLNe/Dycmeuyd" // 必须，上一步中使用 RSA签名验签工具 生成的私钥
	var client, err = alipay.New("2021000149637341", privateKey, false)
	if err != nil {
		fmt.Println(err)
		return ""
	}
	var p = alipay.TradeWapPay{}
	p.NotifyURL = "http://794554d6.r31.cpolar.top/pay/return"
	p.ReturnURL = "https://www.baidu.com/"
	p.Subject = Ali.Title
	p.OutTradeNo = Ali.OrderNo
	p.TotalAmount = fmt.Sprintf("%.2f", Ali.Price)
	p.ProductCode = "QUICK_WAP_WAY"

	var url, errs = client.TradeWapPay(p)
	if errs != nil {
		fmt.Println(errs)
	}
	// 这个 payURL 即是用于打开支付宝支付页面的 URL，可将输出的内容复制，到浏览器中访问该 URL 即可打开支付页面。
	var payURL = url.String()
	return payURL
}
